﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

using System.Data.SqlClient;

namespace TextMIS
{
    public partial class frmFillIn : Form
    {
        public frmFillIn()
        {
            InitializeComponent();
        }
        public static string userName;
        SqlConnection conn;
        SqlDataAdapter da;
        SqlCommand com;

        public static string strValue;
        private void frmFillIn_Load(object sender, EventArgs e)
        {
            conn = new
             SqlConnection(frmLogin.SQLstr);
            userName = frmLogin.userName;



            this.cbxSex.Items.Add("男");
            this.cbxSex.Items.Add("女");


            
            this.ShowInfo();
        }


        private void btnOk_Click(object sender, EventArgs e)
        {
            
            string sSQL= "INSERT INTO PatientInfo (RegisterID,Pname,Psex,Pphone,Paddress,Username) " +
                                            "VALUES ('" + txtRegisNum.Text.Trim() +
                                                "','" + txtName.Text.Trim() +
                                                "','" + cbxSex.Text.Trim() +
                                                "','" + txtTel.Text.Trim() +
                                                "','" + txtAddress.Text.Trim()+
                                                "','" + userName + "')";

            com = new SqlCommand(sSQL, conn);

            if (conn.State == ConnectionState.Closed)
            {
                conn.Open();
            }

            com.ExecuteNonQuery();
            conn.Close();
            MessageBox.Show("填写成功！");


        }

        private void btnExit_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void groupBox1_Enter(object sender, EventArgs e)
        {

        }

        private void tcbCondition_Click(object sender, EventArgs e)
        {

        }


        private void ShowInfo()
        {
            try
            {
                //listView1.Clear();
                strValue = "select [Pname],[Psex],[Pphone],[Paddress] from PatientInfo ";
                da = new SqlDataAdapter(strValue, conn);

                DataTable dt = new DataTable();
                if (conn.State == ConnectionState.Closed)
                {
                    conn.Open();
                }
                int count = da.Fill(dt);
                conn.Close();

                dataGridView1.DataSource = dt;

                //SetupHeaderLIST();
                //foreach (DataRow dr in dt.Rows)
                //{
                //    ListViewItem lvi = new ListViewItem();
                //    lvi.SubItems.Clear();
                //    lvi.SubItems[0].Text = dr[0].ToString();
                //    lvi.SubItems.Add(dr[1].ToString());
                //    lvi.SubItems.Add(dr[2].ToString());
                //    listView1.Items.Add(lvi);
                //}

            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }

        //private void SetupHeaderLIST()
        //{
        //    listView1.Columns.Add("姓名", 100, HorizontalAlignment.Left);
        //    listView1.Columns.Add("性别", 120, HorizontalAlignment.Left);
        //    listView1.Columns.Add("手机号", 100, HorizontalAlignment.Left);
        //    listView1.Columns.Add("地址", 200, HorizontalAlignment.Left);
        //}

        private void listView1_SelectedIndexChanged(object sender, EventArgs e)
        {

        }

        private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e)
        {

        }
    }
}
